Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds shake command #2259

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ivanacostarubio
Copy link

Proposed changes

It implements the shake command. It closes #1164

AI

copilot:summary

Testing

I was able to test this using my local iOS simulator. However, I'm unsure why it's not working on the Android emulator. I can see the shake happening when I use the terminal to run the adb commands.

Issues fixed

@Fishbowler Fishbowler added the v1.40.0 Release 1.40.0 label Feb 5, 2025
if (exitCode != 0) {
val errorStream = process.errorStream.bufferedReader().readText()
logger.error("Failed to execute shake gesture. Exit code: $exitCode, Error: $errorStream")
throw IOException("Failed to execute shake gesture on simulator. Exit code: $exitCode")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catch block below will re-throw this with this message wrapped in the same message again:
"Failed to execute shake gesture on simulator: Failed to execute shake gesture on simulator. Exit code: $exitCode"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. 68212e0

logger.error("Failed to execute shake gesture. Exit code: $exitCode, Error: $errorStream")
}

logger.trace("Successfully executed shake gesture")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now if exitCode != 0 you will log the error, but don't do anything about it and you'll log this 'Successful' message and return normally.

Sorry I wasn't more clear in the earlier review. I'd suggest bringing the previous throw back, so the function exits properly on error. But something else needs to change to avoid the double message.

I thought of two options.

  1. cut down the message: throw IOException("Exit code: $exitCode") and the outer catch/throw will use that as the error message.
  2. Move the code that checks the exitCode outside the try block (everything from 'if' on 198 to 'logger.trace' on 203). That way so the throw IOException can throw directly to the calling function. That means the calling function will get the exception as IOException instead of XCUITestServerError.UnknownFailure.

Copy link

@rtharston rtharston left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I was writing the other comment about the deleted 'throw' I decided to look at the rest of the XCTestDriverClient file for other examples of throwing exceptions, and I noticed that this function is different from all the others that call executeJsonRequest. Looks like you need to move all this code to a new Handler file in /Maestro/maestro-ios-xctest-runner/maestro-driver-iosUITests/Routes/Handlers/ (and add a new case to the Rouse enum in XCTestHTTPServer.swift and handle that case in createRouteHandler in RouteHandlerFactory.swift).

Then instead of throwing exceptions you'll want to return HTTP errors.

Of course, this is all from looking at this file for a few minutes, I'm not one of the original developers, so we'll want one of them to chime in as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v1.40.0 Release 1.40.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Shake Simulation
3 participants